﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;


namespace ZG_member
{
    public partial class LeaveAdd : Form
    {
        public LeaveAdd(string memID)
        {
            InitializeComponent();
            this.Opacity = 0;
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            memberID = memID;
        }
        public LeaveAdd(ZG_member.Model.Leave leave)
        {
            InitializeComponent();
            this.Opacity = 0;
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            leaveMode = leave;
        }
        string memberID="0";
        ZG_member.Model.Leave leaveMode;
        private void button1_Click(object sender, EventArgs e)
        {
            ZG_member.BLL.operatorInfo opera = new ZG_member.BLL.operatorInfo();
            ZG_member.Model.operatorInfo opInfoMod = new ZG_member.Model.operatorInfo();
            ZG_member.BLL.roleInfo role = new ZG_member.BLL.roleInfo();
            ZG_member.Model.roleInfo roleMode = new ZG_member.Model.roleInfo();
            opInfoMod = opera.GetModelList("username='" + MainForm.Operator + "'")[0];
            roleMode = role.GetModel(Convert.ToInt32(opInfoMod.roleId));
            if (roleMode.roleInfo1[39].ToString() == "0")
            {
                MessageBox.Show("您没有修改请假时间的权限！");
                return;
            }

            

            ZG_member.BLL.Leave leave = new ZG_member.BLL.Leave();
            ZG_member.Model.Leave leaMode = new ZG_member.Model.Leave();
            if (this.Text != "请假修改")
            {

                leaMode.memberId = this.txtMemberID.Text;
                if (this.dtpStartTime.Value > this.dtpEndTime.Value)
                {
                    MessageBox.Show("时间顺序输入有误！请重新输入！");
                    return;
                }
                leaMode.StartDate = Convert.ToDateTime(this.dtpStartTime.Text);
                leaMode.EndDate = Convert.ToDateTime(this.dtpEndTime.Text);
                leave.add(leaMode);
                MessageBox.Show("添加成功！");
            }
            else
            {
                if (this.dtpStartTime.Value > this.dtpEndTime.Value)
                {
                    MessageBox.Show("时间顺序输入有误！请重新输入！");
                    return;
                }
                leaveMode.StartDate = Convert.ToDateTime(this.dtpStartTime.Text);
                leaveMode.EndDate = Convert.ToDateTime(this.dtpEndTime.Text);
                leave.Update(leaveMode);
                MessageBox.Show("修改成功");
            }

            this.Close();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //timer开启
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();

            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            //timer关闭
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
                //mainform.TxtCardId.Focus();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        int flag = 0;
        private void LeaveAdd_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                this.timer2.Start();
            }
        }

        private void LeaveAdd_Load(object sender, EventArgs e)
        {
            this.timer1.Start();
            ZG_member.BLL.memberInfo member = new ZG_member.BLL.memberInfo();
            ZG_member.Model.memberInfo memberMode = new ZG_member.Model.memberInfo();
            if (memberID != "0")
            {
                memberMode = member.GetModels(memberID);
                this.txtMemberID.Text = memberMode.memberId;
                this.txtMemberName.Text = memberMode.memberName;
                this.dtpStartTime.Value =Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                this.dtpEndTime.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));

            }
            else if (leaveMode != null)
            {
                this.Text = "请假修改";
                memberMode= member.GetModels(leaveMode.memberId);
                this.txtMemberID.Text = memberMode.memberId;
                this.txtMemberName.Text = memberMode.memberName;
                this.dtpStartTime.Value = leaveMode.StartDate;
                this.dtpEndTime.Value = leaveMode.EndDate;
            }
        }
    }
}
